package com.gable.exhibition.service.impl;

import com.gable.common.util.ReturnResultUtil;
import com.gable.exhibition.dao.FileDao;
import com.gable.exhibition.model.File;
import com.gable.exhibition.service.FileUploadService;
import com.gable.exhibition.util.MessageUtil;
import com.gable.exhibition.view.FileView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Lesson on 2018/2/24.
 */
@Service("fileUploadService")
public class FileUploadServiceImpl implements FileUploadService {

    @Autowired
    FileDao fileDao;

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public ReturnResultUtil saveFileUpload(List<File> fileList) {
        for(File file : fileList){
            fileDao.insertSelective(file);
        }
        return new ReturnResultUtil(200, MessageUtil.SAVESUCCESS,fileList);
    }

    @Override
    public ReturnResultUtil queryFileList(FileView fileView) {
        List<FileView> fileViews = fileDao.queryFiles(fileView);
        return new ReturnResultUtil(200,MessageUtil.QUERYSUCCESS,fileViews);
    }
}
